import { request, config } from 'utils'
const { api } = config
const { testPlans,products,testSuites,testPlan,suts,testHosts,releaselist,execute,executeResult} = api

export async function query (params) {
  return request({
    url: testPlans,
    method: 'get',
    data: {
      page:Number(params.page)||1,
      limit:10
    },
  })
}
export async function productquery (params) {
  return request({
    url: products,
    method: 'get',
    data: {
      page:1,
      limit:-1
    },
  })
}
export async function suitequery (params) {
  return request({
    url: testSuites,
    method: 'get',
    data: {
      page:1,
      limit:-1
    },
  })
}

export async function sutquery (params) {
  return request({
    url: suts,
    method: 'get',
    data: {
      page:1,
      limit:-1
    },
  })
}
export async function testhostquery (params) {
  return request({
    url: testHosts,
    method: 'get',
    data: {
      page:1,
      limit:-1
    },
  })
}
export async function releasequery (params) {
  return request({
    url: releaselist,
    method: 'get',
    data: {
      page:1,
      limit:-1,
      product_name_id:params
    },
  })
}



export async function save (params) {
  let data=''
  for( let index in params){
    if(params[index]){
      data+=index+"="+params[index]+"&"
    }
  }
  data=data.slice(0,-1)
  return request({
    url: testPlan+'/add/',
    method: 'post',
    data: data,
  })
}


export async function executePlan (params) {
  let data=''
  for( let index in params){
    if(params[index]){
      data+=index+"="+params[index]+"&"
    }
  }
  data=data.slice(0,-1)
  return request({
    url: execute,
    method: 'post',
    data: data,
  })
}

export async function getResult (params) {
  return request({
    url: executeResult,
    method: 'get',
    data:{
      limit:1,
      page:1,
      testResultId:params
    }
  })
}
